package com.stellar.circle.basic.service.impl;

import com.stellar.circle.basic.dao.SPostCategoryDao;
import com.stellar.circle.basic.entity.SPostCategory;
import com.stellar.circle.basic.service.SPostCategoryService;
import com.stellar.web.core.enums.IsDeletedFlagEnum;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 帖子分类表(SPostCategory)服务实现
 *
 * @author Jqchan
 * @since 2025-05-17 19:12:02
 */
@Service
public class SPostCategoryServiceImpl implements SPostCategoryService {

    @Resource
    private SPostCategoryDao sPostCategoryDao;

    @Override
    public SPostCategory queryById(Long id) {
        return sPostCategoryDao.queryById(id);
    }

    @Override
    public SPostCategory queryByCondition(SPostCategory condition) {
        return sPostCategoryDao.queryByCondition(condition);
    }

    @Override
    public List<SPostCategory> queryAllByCondition(SPostCategory condition) {
        return sPostCategoryDao.queryAllByCondition(condition);
    }

    @Override
    public List<SPostCategory> page(SPostCategory condition, int page, int pageSize) {
        return sPostCategoryDao.page(condition, page, pageSize);
    }

    @Override
    public int insert(SPostCategory entity) {
        return sPostCategoryDao.insert(entity);
    }

    @Override
    public int update(SPostCategory entity) {
        return sPostCategoryDao.update(entity);
    }

    @Override
    public int deleteById(Long id) {
        return sPostCategoryDao.deleteById(id);
    }

    @Override
    public Long count(SPostCategory condition) {
        return sPostCategoryDao.count(condition);
    }

    @Override
    public Map<Long, String> batchQueryCategoryNames(List<Long> categoryIds) {
        if (categoryIds == null || categoryIds.isEmpty()) {
            return Collections.emptyMap();
        }

        List<SPostCategory> categories = sPostCategoryDao.batchSelectByIds(categoryIds);

        return categories.stream()
                .filter(c -> c.getIsDeleted() == IsDeletedFlagEnum.UN_DELETED.getVal())
                .collect(Collectors.toMap(
                        SPostCategory::getId,
                        SPostCategory::getCategoryName,
                        (existing, replacement) -> existing
                ));
    }
}
